package com.ctr_flower.service.impl;

import com.ctr_flower.entity.TbMerchant;
import com.ctr_flower.dao.TbMerchantDao;
import com.ctr_flower.service.TbMerchantService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TbMerchant)表服务实现类
 *
 * @author makejava
 * @since 2020-08-23 12:06:00
 */
@Service("tbMerchantService")
public class TbMerchantServiceImpl implements TbMerchantService {
    @Resource
    private TbMerchantDao tbMerchantDao;

    /**
     * 通过ID查询单条数据
     *
     * @param merchantId 主键
     * @return 实例对象
     */
    @Override
    public TbMerchant queryById(Integer merchantId) {
        return this.tbMerchantDao.queryById(merchantId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<TbMerchant> queryAllByLimit(int offset, int limit) {
        return this.tbMerchantDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param tbMerchant 实例对象
     * @return 实例对象
     */
    @Override
    public TbMerchant insert(TbMerchant tbMerchant) {
        this.tbMerchantDao.insert(tbMerchant);
        return tbMerchant;
    }

    /**
     * 修改数据
     *
     * @param tbMerchant 实例对象
     * @return 实例对象
     */
    @Override
    public TbMerchant update(TbMerchant tbMerchant) {
        this.tbMerchantDao.update(tbMerchant);
        return this.queryById(tbMerchant.getMerchantId());
    }

    /**
     * 通过主键删除数据
     *
     * @param merchantId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer merchantId) {
        return this.tbMerchantDao.deleteById(merchantId) > 0;
    }
}